#pragma once
#include<graphics.h>
#include<vector>
#include<iostream>
using namespace std;
#pragma comment(lib,"MSIMG32.LIB")
static inline void putimage_a(int x, int y, IMAGE* a)
{
	int w = a->getwidth();
	int h = a->getheight();
	AlphaBlend(GetImageHDC(NULL), x, y, w, h, GetImageHDC(a), 0, 0, w, h, { AC_SRC_OVER,0,255,AC_SRC_ALPHA });
}
class Atlas
{
public:
	vector <IMAGE*> framelist;
public:
	Atlas(LPCTSTR path, int num)
	{
		TCHAR path_file[256];
		for (size_t i = 0; i < num; i++)
		{
			_stprintf_s(path_file, path, i);
			IMAGE* picture = new IMAGE();
			loadimage(picture, path_file);
			framelist.push_back(picture);
		}
	}
	~Atlas()
	{
		for (size_t i = 0; i < framelist.size(); i++)
		{
			delete framelist[i];
		}
	}
};


class Picture
{
public:
	Picture(Atlas* altas, int time)
	{
		time_ms = time;
		animatlas = altas;
	}
	void Play(int x, int y, int detla)
	{
		timer += detla;
		if (timer >= time_ms)
		{
			//idx_picture = 1;
			idx_picture = (idx_picture + 1) % (animatlas->framelist.size());
			timer = 0;
		}
		putimage_a(x, y, animatlas->framelist[idx_picture]);
	}

private:
	int timer = 0;
	int idx_picture = 0;
	int time_ms;
	Atlas* animatlas;

};
